import vue from '@vitejs/plugin-vue'
import { defineConfig, loadEnv } from 'vite'

// https://vitejs.dev/config/
export default defineConfig(({ mode }) => {
  // process.env = { ...process.env, ...loadEnv(mode, process.cwd()) }
  process.env = Object.assign(process.env, loadEnv(mode, process.cwd()));

  return {

    plugins: [vue()],
    base: './',
    build: {
      outDir: 'dist'
    },
    server: {
      port: 4001,
      open: true,
      proxy: {
        '/api': {
          target: 'http://localhost:8080',
          changeOrigin: true,
          rewrite: (path) => path.replace(/^\/api/, '')
        },
        '/img': {
          target: 'http://127.0.0.1:5000',
          changeOrigin: true,
          rewrite: path => path.replace(/^\/img/, '')
        }
      }
    }
  }
})
